#ifndef HIGH_PID_H
#define HIGH_PID_H

#include "drv.h"

typedef struct
{
    float Ref;            // Input: Reference input
    float Fdb;            // Input: Feedback input
    float Err;                // Variable: Error
    float Kp;                // Parameter: Proportional gain
    float Up;                // Variable: Proportional output
    float Ui;                // Variable: Integral output
    float Ud;                // Variable: Derivative output
    int32_t OutPreSat;        // Variable: Pre-saturated output
    int32_t OutMax;            // Parameter: Maximum output
    int32_t OutMin;            // Parameter: Minimum output
    int32_t Out;            // Output: PID output
    int32_t SatErr;            // Variable: Saturated difference
    float Ki;                // Parameter: Integral gain
    float Kc;                // Parameter: Integral correction gain
    float Kd;                // Parameter: Derivative gain
    float Up1;                // History: Previous proportional output
    float last_d;                // History: Derivative  output
    float Ts;                // Ts
//    void (*calc)();        // Pointer to calculation function
} PID_struct;

typedef PID_struct *PIDREG3_handle;

#define PID_MAX (0xff0)
#define PID_MIN (0x10)
/*温度PID*/
#define PID_TEMP_KP (5)
#define PID_TEMP_KI (10)
#define PID_TEMP_KD (10)

#define PID_TEMP_KC (1.2)

#define PID_TEMP_TS (1)

#define PID_TEMP_DEFAULTS { 100, \
                           0, \
                           0, \
                           PID_TEMP_KP , \
                           0, \
                           0, \
                           0, \
                           0, \
                           PID_MAX , \
                           PID_MIN , \
                           0, \
                           0, \
                           PID_TEMP_KI , \
                           PID_TEMP_KC , \
                           PID_TEMP_KD , \
                           0,0,PID_TEMP_TS }
//                          (void (*)(Uint32))pid_func }

#define PID_POWER_KP (0.05)
#define PID_POWER_KI (5)

#define PID_POWER_KD (0)

#define PID_POWER_KC (3.0)

#define PID_POWER_TS (0.01)

#define PID_POWER_DEFAULTS { 0, \
                           0, \
                           0, \
                           PID_POWER_KP , \
                           0, \
                           0, \
                           0, \
                           0, \
                           PID_MAX , \
                           PID_MIN , \
                           0, \
                           0, \
                           PID_POWER_KI , \
                           PID_POWER_KC , \
                           PID_POWER_KD , \
                           0,0,PID_POWER_TS}

void pid_func(PID_struct *v);

extern PID_struct PID_power_st;

extern PID_struct PID_temp_st;

void pid_init(PID_struct *v);

void pid_func_new(PID_struct *v);
#endif
